/*
 * @PageName: 
 * @Description: 离开浏览器标签后切换回该标签重新刷新页面
 * @FilePath: /glm-mes-pc/src/utils/useVisibilityHandler.js
 */
import { onMounted, onUnmounted } from 'vue';

export function usePageVisibility(callback) {
  // 页面可见性变化时的处理函数
  const handleVisibilityChange = () => {
    if (document.visibilityState === 'visible') {
      callback && typeof callback === 'function' && callback();
    }
  };

  // 设置挂载时的生命周期钩子
  onMounted(() => {
      document.addEventListener('visibilitychange', handleVisibilityChange);
  });

  // 设置卸载时的生命周期钩子
  onUnmounted(() => {
      document.removeEventListener('visibilitychange', handleVisibilityChange);
  });
}

